package com.dejiao.service.impl;


import com.dejiao.dao.PasswordEntityDao;
import com.dejiao.entity.po.PasswordEntity;
import com.dejiao.service.PeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * Created by Germmy on 2018/5/20.
 */
@Service
public class PeServiceImpl implements PeService {

    @Autowired
    PasswordEntityDao passwordEntityDao;


    @Override
    public int insert(PasswordEntity passwordEntity) {
        //需要将默认字段补齐
        passwordEntity.setPeId(UUID.randomUUID().toString());
        passwordEntity.setCreater("admin");
        passwordEntity.setCreateTime(new Date());
        passwordEntity.setUpdator("admin");
        passwordEntity.setUpdateTime(new Date());
        passwordEntity.setIsDeleted(0);
        passwordEntity.setVersion(0L);
        return passwordEntityDao.insert(passwordEntity);
    }

    @Override
    public PasswordEntity selectByWebSiteName(String webSiteName) {
        return passwordEntityDao.selectByWebSiteName(webSiteName);
    }

    @Override
    public int updateByPrimaryKeySelective(PasswordEntity passwordEntity) {
        //将更新时间、版本号+1
        passwordEntity.setUpdateTime(new Date());
        return passwordEntityDao.updateByPrimaryKeySelective(passwordEntity);
    }

    @Override
    public List<String> selectListByWebSiteName(String webSiteName) {
        return passwordEntityDao.selectListByWebSiteName(webSiteName);
    }

    @Override
    public int deleteByPrimaryKey(String peId) {
        return passwordEntityDao.deleteByPrimaryKey(peId);
    }

    @Override
    public int deleteByWebSiteName(String webSiteName) {
        return passwordEntityDao.deleteByWebSiteName(webSiteName);
    }
}
